package com.example.personnel_management_system.util;

import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

import java.util.Random;

@Component
public class Tool {
    public String getCheckCode(){
        Random r = new Random();
        char nums[]=new char[8];
        for(int i=0;i<4;i++) {
            nums[i]=(char) ('0'+r.nextInt(10));
            nums[i+4]=(char) ('a'+r.nextInt(26));
        }
        String text="";
        for(int i=0;i<4;i++) {
            text+=nums[r.nextInt(8)];
        }
        return text;
    }
    public String MD5(String salt,String password){
        String result=password;
        for(int i=0;i<3;i++)
            result= DigestUtils.md5DigestAsHex((salt+result+salt).getBytes());
        return result;
    }
}
